
//Copyright 1997-2009 Syrinx Development, Inc.
//This file is part of the Syrinx Web Application Framework (SWAF).
// == BEGIN LICENSE ==
//
// Licensed under the terms of any of the following licenses at your
// choice:
//
//  - GNU General Public License Version 3 or later (the "GPL")
//    http://www.gnu.org/licenses/gpl.html
//
//  - GNU Lesser General Public License Version 3 or later (the "LGPL")
//    http://www.gnu.org/licenses/lgpl.html
//
//  - Mozilla Public License Version 1.1 or later (the "MPL")
//    http://www.mozilla.org/MPL/MPL-1.1.html
//
// == END LICENSE ==
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Text;
using System.Xml;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Swaf.BizObj;

[assembly: WebResource("Syrinx.Gui.AspNet.resizer.js", "application/x-javascript")]
namespace Syrinx.Gui.AspNet
{
	[ParseChildren(false)]
	public class DivResize : System.Web.UI.UserControl
	{
		protected int s_w = 400;
		protected int s_h = 450;

		[Category("Appearance")]
		public int Width { get { return s_w; } set { s_w= value; } }
		
		[Category("Appearance")]
		public int Height { get { return s_h; } set { s_h = value; } }

		protected override void OnPreRender(EventArgs e)
		{
			base.OnPreRender(e);
			string name = GetType().Namespace + ".resizer.js";
			StreamReader sr = new StreamReader(GetType().Assembly.GetManifestResourceStream(name));
			string script = sr.ReadToEnd();
			sr.Close();
			Page.ClientScript.RegisterClientScriptBlock(GetType(), "DivResizerCtl", script, true);

		}
		protected override void OnLoad(EventArgs e)
		{
			base.OnLoad(e);
			Page.ClientScript.RegisterClientScriptBlock(GetType(), "ResizeLoader", init_script(this.ID), true);
		}
		protected static string init_script(string id)
		{
			return string.Format("sr=new DivResizer(document.getElementById('sizeArea'),document.getElementById('{0}_baseBody_designEditorArea'))\n;",id);
		}
		protected override void Render(HtmlTextWriter writer)
		{
			writer.Write(string.Format(s_ctlHtml,Width,Height));
			RenderChildren(writer);
			writer.Write("</div>");
		}
		protected static string s_ctlHtml = "<div id='sizearea' style='width:{0}px;height:{1}px;border-width:thin;border-style:solid;' onmousedown='start()'>";

		protected override void AddParsedSubObject(object obj)
		{
			this.Controls.Add((System.Web.UI.Control)obj);
		}
	}

}
